#! /bin/sh

set -x
# Shell to run a program to extract bed reflections from diffractions and
# noise for stacked data, with ps obtained via minimization of cross-entropy
# and slant stacks computed via radon transform

# input and output files
MYDATA=.
input1=syn2.data.test
output1=ref.data
output2=diff.data
separation=suharlan

# initialize output files
>$output1
>$output2

# control flags
gopt=3
scl=1			# =-1 use inverse transform of noise 
			# =0 not to apply trace scaling
			# =1 apply scaling trace by trace
			# =2 apply scaling by time slices
			# =3 apply both scalings 
anenv=1			# =0 not to consider analytic envelopes
			# =1 for signed analytic envelopes
			# =2 for positive analytic envelopes
			# =3 for negative analytic envelopes
			# =4 signed square of analytic envelopes
			# =5 positive square of analytic envelopes
			# =6 negative square of analytic envelopes
rgt=2			# =1 for flat random number generator
			# =2 for gaussian random number generator
sts=1	                # =0 not to apply smoothing
			# =1 for damped least squares smoothing
verbose=1		# =1 to print processing information 
norm=1			# =1 to normalize reliability values

# general parameters
c=0.04			# maximum allowed error to compute reliability 
rel1=0.000001		# minimum reliability for reliable samples (first pass)
rel2=0.00068		# minimum reliability for reliable samples (second pass)
niter=2                 # number of iterations
seed=1			# seed for random number generator
sditer=5		# number of steepest descent iterations to compute ps
nintlh=50		# number of intervals (bins) in histograms
dx=20.0                 # horizontal sampling interval
fx=0.0			# offset of first trace
nt=600			# number of vertical samples
dt=0.004		# vertical sampling interval

# taup input parameters (for suradon)
offref=1980.            # maximum offset
pmin=-1188              # minimum moveout in ms on reference offset
pmax=1188               # maximum moveout in ms on reference offset
dp=24                   # moveout increment in ms on reference offset
prewhite=0.01          	# prewhitening
ninterp=0               # number of traces to interpol between each input trace

# smoothing parameteres 
r1=10			# vertcal smoothing factor for dlsq smoothing
r2=1			# horizontal smoothing factor for dlsq smoothing

# plotting parameters
nbpi=72			# number of bits per inch
f2=1			# first horizontal sample			
d2=1			# horizontal increment
ts=14			# title size
ls=12			# label size
clip1=1.5		# clip from synthetic data
clip2=50.		# clip for taup data

# call program to extract diffractions and noise
suharlan < $input1 gopt=$gopt anenv=$anenv sts=$sts scl=$scl plot=$plot rgt=$rgt \
	dx=$dx nintlh=$nintlh sts=$sts niter=$niter seed=$seed sditer=$sditer \
	offref=$offref pmin1=$pmin pmax1=$pmax dp=$dp prewhite=$prewhite \
	ninterp=$ninterp c=$c rel1=$rel1 rel2=$rel2 r1=$r1 r2=$r2 \
	verbose=$verbose norm=$norm signal=$output1 noise=$output2 


# plot final results
suxwigb < $output1 label1="time (s)" nbpi=$nbpi \
        title="Reflections anenv=$anenv sts=$sts scl=$scl" \
        label2="trace number" xbox=600 f2=$f2 d2=$d2 titlesize=$ts labelsize=$ls &
suxwigb < $output2 label1="time (s)" nbpi=$nbpi \
        title="Diffractions anenv=$anenv sts=$sts scl=$scl" \
        label2="trace number" xbox=300 ybox=150 f2=$f2 d2=$d2 titlesize=$ts labelsize=$ls &
exit
